package com.xiao.demo;

import com.alibaba.fastjson.JSONObject;
import org.assertj.core.util.Lists;
import org.junit.Test;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @author QuanZhao.Xiao
 * @description
 * @date 2022/1/11 11:07:32
 */
public class Case20220111 {
    @Test
    public void testBigDecimal() {
        DecimalFormat df = new DecimalFormat("0%");
        String s = df.format(new BigDecimal("0.01832"));
        System.out.println(s);

        BigDecimal b1 = new BigDecimal("1");
        BigDecimal b2 = new BigDecimal(1);
        System.out.println(b1.compareTo(b2) >= 0);
        System.out.println(b1.equals(b2));

        System.out.println(new BigDecimal("0.01832").toString());
    }

    @Test
    public void testLocalDate() {
        LocalDate date = LocalDate.parse("2022-10-11");
        System.out.println(date.getMonth().getValue());
        System.out.println(date.getMonthValue());
    }

    @Test
    public void testRestoreBizKey() {
        String bizKey = "1_2";
        String UNDER_LINE = "_";
        String[] bizKeys = bizKey.split(UNDER_LINE);
        JSONObject bizKeyObj = new JSONObject();
        bizKeyObj.put("userId", bizKeys[0]);
        bizKeyObj.put("activityId", bizKeys[1]);
        System.out.println(bizKeyObj);
    }

    @Test
    public void testUUID() {
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));
    }

    @Test
    public void testArrays() {
        List<String> list = Arrays.asList("1", "2", "3");
        try {
            list.get(0);
        } catch (UnsupportedOperationException e) {
            e.printStackTrace();
        }
        System.out.println(list);
        System.out.println("-----------");
        list = Lists.newArrayList("5");
        System.out.println(list);
    }
}
